/**
 * Copyright (C) 2013 Christos Koufogiannakis
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 *     
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.easychart.demo;

import java.util.ArrayList;

import com.easychart.chart.PieChart;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

/**
 * Example with non full screen PieChart that updates based
 * on user input.
 */
public class ExamplePieChartDynamic extends Activity{
	Button button1, button2;
	EditText editText1, editText2;
	PieChart pieChart;
		
	ArrayList<String> labels =  new ArrayList<String>();
	ArrayList<Double> values =  new ArrayList<Double>();
	
	@Override
	public void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.piechartdynamic);
		
		editText1 = (EditText)  findViewById(R.id.pieEditText1);
		editText2 = (EditText)  findViewById(R.id.pieEditText2);		
		pieChart = (PieChart) findViewById(R.id.easyMobileChartPieView);
		button1 = (Button)  findViewById(R.id.togglePiebutton);	
		button2 = (Button)  findViewById(R.id.addPieButton);	
			
		button1.setOnClickListener(new OnClickListener() {
		    public void onClick(View v) {
		    	pieChart.getParameters().SHOW_LEGEND.setValue(
		    			!pieChart.getParameters().SHOW_LEGEND.getValue());
		    	pieChart.refresh();
		    } 
		});
				
		button2.setOnClickListener(new OnClickListener() {
		    public void onClick(View v) {
		    	String label = editText1.getText().toString();
		    	double value = Double.parseDouble(editText2.getText().toString());
		    	labels.add(label);
		    	values.add(value);
		    	pieChart.refresh();
		    } 
		});
		
		pieChart.setValuesAndLabels(values, labels);
		pieChart.setPlotTitle("Dynamic PieChart");
	}
}
